package com.self.cgqcompose.ui.components.areacode

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.self.cgqcompose.beans.AreaBlock
import com.self.cgqcompose.common.ConstantsUi
import com.self.cgqcompose.mock.MockJson

/**水平滑动 竖图*/
@Composable
fun AreaCode145(data: AreaBlock) {
    Column(
        modifier = Modifier
            .padding(horizontal = ConstantsUi.HOME_MARGIN),
        verticalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        BlockTitle(data)
        LazyRow(modifier = Modifier,
            horizontalArrangement = Arrangement.spacedBy(ConstantsUi.HOME_ITEM_SPACING)) {
            items(data.data.data.size) { index ->
                Column(
                    modifier = Modifier
                        .width(108.dp)) {
                    AsyncImage(model = data.data.data[index].cover, contentDescription = null,
                        modifier = Modifier.size(108.dp, 144.dp)
                            .clip(RoundedCornerShape(5.dp)),
                        contentScale = ContentScale.Crop)
                    Text(text = data.data.data[index].title, modifier = Modifier.fillMaxWidth(),
                        fontSize = 14.sp, textAlign = TextAlign.Start, maxLines = 1)
                }
            }
        }
    }

}

@Preview(showBackground = true, backgroundColor = 0xffffffff)
@Composable
fun AreaCode145Preview() {
    val context = LocalContext.current;
    val area9 = MockJson.loadMockDataArea9(context)
    AreaCode145(area9.data[4])
}